import globalConfig from "@/utils/config.js";
import matomo from "@/utils/matomo/index";
import Vue from "vue";
import App from "./App";
import "./router";
import store from "./store";
import "./utils/funcs";

Vue.config.productionTip = false;

Vue.prototype.$store = store;

App.mpType = "app";
const reportUrl = globalConfig.ana_url;
const siteId = globalConfig.siteId;
const tracker = matomo.initTracker(reportUrl, siteId, {});
Vue.mixin({
  /**
   * 混入 onload，发请求
   */
  onLoad(options) {
    if (!this.matomo) {
      this.matomo = tracker;
      getApp().matomo = tracker;
    }
    matomo._pageOnLoad.call(this, options);
  },
  methods: {
    async setTabBarIndex(index) {
      if (this.$mp && this.$mp.page && typeof this.$mp.page.getTabBar === "function" && this.$mp.page.getTabBar()) {
        this.$mp.page.getTabBar().setData({
          selected: index
        });
      }
    }
  },
  /**
   * 混入分享页面
   * @param {}} options
   */
  onShareAppMessage(options) {
    if (!this.matomo) {
      this.matomo = tracker;
      getApp().matomo = tracker;
    }
    matomo._pageOnShareAppMessage.call(this, options);
  }
});
const app = new Vue({
  store,
  ...App
});
app.$mount();
